package com.woniuxy.house.admin;

import com.woniuxy.house.entity.Comment;
import com.woniuxy.house.entity.PageBean;
import com.woniuxy.house.entity.Post;
import com.woniuxy.house.entity.Source;
import com.woniuxy.house.service.CommentService;
import com.woniuxy.house.utils.JwtUtil;
import com.woniuxy.house.vo.CommentVo;
import com.woniuxy.house.vo.ResponseEntity;
import com.woniuxy.house.vo.SourceVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.jar.JarEntry;

@RestController("admincommentcontroller")
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private JwtUtil jwtUtil;
    @Autowired
    private CommentService commentService;

    @RequestMapping("/list")
    public ResponseEntity list(@RequestHeader String jwt){
        if (jwtUtil.verifyJWT(jwt)) {
            return new ResponseEntity("200", "OK", commentService.getByPage(1));
        } else {
            return new ResponseEntity("700", "令牌失效", "null");
        }
    }

    @RequestMapping("/getpage/{page}")//后续的分页查询
    public ResponseEntity getPage(@PathVariable int page){
        PageBean<Comment> byPage = commentService.getByPage(page);
        return   new ResponseEntity("200","成功",byPage);
    }

    //多条件查询评论
    @RequestMapping("/condition")
    public ResponseEntity getByCondition(@RequestBody CommentVo commentVo){

        PageBean<Comment> byCondition = commentService.getByCondition(commentVo);
        return new ResponseEntity("200","成功",byCondition);
    }

    @RequestMapping("/update")
    public ResponseEntity update(@RequestHeader Comment comment){
        commentService.updateComment(comment);
        return ResponseEntity.SUCCESS;
    }

    @RequestMapping("/delete/{id}")
    public ResponseEntity datele(@PathVariable Integer id){
        commentService.deleteComment(id);
        return ResponseEntity.SUCCESS;
    }
    @RequestMapping("/reset")
    public ResponseEntity reset(){
        PageBean<Comment> byPage = commentService.getByPage(1);
        return  new ResponseEntity("200","成功",byPage);
    }
}
